package com.ddd.demo.test;

public class ShellSort {

    public static void main(String[] args) {

        Integer[] arr = new Integer[]{2, 3, 1, 4, 5};
        shellSort(arr);

    }

    private static void shellSort(Integer[] arr) {
        int length = arr.length;
        for (int gap = length / 2; gap >0 ; gap /=2) {
            for (int i = gap; i < length; i++) {
                int temp = arr[i];
                int j;
                for (j = i; j >= gap && arr[j-gap] > temp ; j-=gap) {
                    arr[j] = arr[j-gap];
                }
                arr[j] = temp;
            }
        }
        for (int i = 0; i < length; i++) {
            System.out.println("arr[i] = " + arr[i]);
        }
    }


}
